<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html>
<html>
<head>
	<jsp:include page="/include.jsp"/> 
	<script type="text/javascript">
	 $(document).ready(function(){
		 if('10001'=='${sessionInfo.role.roleid}'){
			 $("#btnQuery").bind("click",doQuery);
			 $('#framework_knowledge_table').datagrid({
					pageSize: 10,
					url :'${pageContext.request.contextPath}/knowledgebase/knowlegeAction!showKnowledgeForPageNew.action',
					queryParams:serializeObject($('#framework_knowledge_table_form')),
					fit:true,
					border:false,
					fitColumns:true,
					pagination:true,
					striped:true,
					pageList:[10,15,20],
					rownumbers:true,
					singleSelect:false,
					pagePosition:'bottom',
					autoRowHeight:true,
					rownumbers:false,
					sortName:'createTime',
					sortOrder:'desc',
					columns:[[  {field:'knowledgeId',checkbox:true}, 
		 						{field:'knowledgeName',title:'知识名称',width:150,align:'left',formatter:function(knowledgeName,rowData,rowIndex){
		 							//return '<a title="'+knowledgeName+'" onclick="doDetail(\''+rowData.knowledgeId+'\')"  style="color:#398ece;cursor:pointer;text-decoration:underline">'+knowledgeName+'</a>';
		 							return '<div  onmouseover="onMouseOverName(this)"  onmouseout="onMouseOutName(this)" onclick="doDetail('+rowData.knowledgeId+')" style="color:#2b76b7;cursor:pointer;width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;" title="'+knowledgeName+'">'+knowledgeName+'</div>';
		 						}},    
		 						{field:'creator',title:'知识作者',width:120,align:'center'},
		 						{field:'createTime',title:'创建时间',width:120,align:'center',sortable:true},
		 						{field:'knowledgeSourceName',title:'来源名称',width:80,align:'center'},
		 						{field:'ww',title:'操作',width:100,align:'center',formatter:function(value,rowData,rowIndex){
								    return '<span  style="cursor:pointer" onclick="doEdit(\''+rowData.knowledgeId+'\')"><img  src="${pageContext.request.contextPath}/images/icons/modify_or_edit.png" title="修改" alt="修改" style="margin-top:2px;"/>修改&nbsp;&nbsp;</span>'		
								           +'<span  style="cursor:pointer" onclick="doDelete(\''+rowData.knowledgeId+'\')"><img  src="${pageContext.request.contextPath}/images/icons/delete.png" title="删除" alt="删除" style="margin-top:2px;"/>删除&nbsp;&nbsp;</span>';
		 						}}
		 					]],
					toolbar:'#framework_knowledge_table_toobar'
				});
		 }else{
			 $("#btnQuery").bind("click",doQueryGeneral);
			 $('#framework_knowledge_table').datagrid({
					url :'${pageContext.request.contextPath}/knowledgebase/knowlegeAction!showKnowledgeForPageNew.action',
					queryParams:serializeObject($('#framework_knowledge_table_form')),
					fit:true,
					border:false,
					fitColumns:true,
					pagination:true,
					striped:true,
					pageList:[10,15,20], 
					singleSelect:false,
					pagePosition:'bottom', 
					autoRowHeight:true,
					rownumbers:false,
					sortName:'createTime',
					columns:[[  
		 						{field:'knowledgeName',title:'知识名称',width:150,align:'left',formatter:function(knowledgeName,rowData,rowIndex){
		 							return '<div  onmouseover="onMouseOverName(this)"  onmouseout="onMouseOutName(this)" onclick="doDetail('+rowData.knowledgeId+')" style="color:#2b76b7;cursor:pointer;width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;" title="'+knowledgeName+'">'+knowledgeName+'</div>';
		 						}},    
		 						{field:'creator',title:'知识作者',width:120,align:'center'},
		 						{field:'createTime',title:'创建时间',width:120,align:'center',sortable:true},
		 						{field:'knowledgeSourceName',title:'来源名称',width:100,align:'center'}
		 					]]
				});
		 }
		 $("#btnReset").bind("click",doReset);
		 //加载知识来源数据
		 $('#knowledge_knowledgeSource').combobox({
				url:'${pageContext.request.contextPath}/knowledgebase/knowlegeAction!initNKnowledgeSrc.action?codeType=requireSrc&tableName=TD_SPEED_REPORT_DEFINE',  
				valueField:'codeValue',
				textField:'codeName',
				panelHeight:'auto',
	  	 		editable:false,
	  	 		onLoadSuccess:function(){
	  				$('#knowledge_knowledgeSource').combobox('setValue',null);
	  			}
		 }); 
		 
		 
// 			//初始化下拉树
// 			$('#knowledge_creator').combotree({  
// 				    url: '${pageContext.request.contextPath}/infopublish/infoPublishAction!getUserTreeInfo.action',  
// 				    parentField : 'pid',
// 				    required: false,
// 				    onSelect:function(node){
// 				    	var obj=node.id.split("@@");
// 				    	if(obj[1]!="parent"){
// 				    		$('#knowledge_creator').val(obj[0]); 
// 				    	}else{
// 				    		$('#knowledge_creator').combotree('clear'); 
// 				    	}
// 			        }
// 				}); 
			
			
			
			//初始化知识作者下拉列表 
			$('#knowledge_creator').combogrid({
				delay: 500,
		        panelWidth:450,  
		        idField:'userid', //ID字段  
		        textField:'username', //显示的字段  
		        mode: 'remote',   
		        url:"${pageContext.request.contextPath}/problemmgr/problemAction!showHandler.action",  
		        fitColumns: true,  
		        striped: true,  
		        editable:false,
		        pagination : true,//是否分页  
		        rownumbers:true,//序号  
		        collapsible:false,//是否可折叠的  
		        fit: true,//自动大小  
		        pageSize: 10,//每页显示的记录条数，默认为10  
		        pageList:[10,20,30],//可以设置每页记录条数的列表  
		        method:'post',  
		        columns:[[{field:'userid',title:'用户ID',width:70,align:'center',sortable:true},				  
						  {field:'username',title:'用户名称',width:75,align:'center',sortable:true}		 
						]],
				toolbar:'#tb'
		    });
			
	 });
		
	function testdialog(){
		//http://192.168.11.200:9502/webetl/basemgr/accuracyRuleConfAction!toAddRulePage.action?metaDataId=350=1
		//var win = window.open("http://localhost:8080/webetl/dqm/knowledgebase/NewFile.html","newwindow","toolbar =no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no,width=500,height:200,left=200,top=100");
		//var win = window.open("http://localhost:8080/webetl/basemgr/accuracyRuleConfAction!toAddRulePage.action?metaDataId=350=1","newwindow","toolbar =no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no,width=800,height:200,left=200,top=100"); 
	} 
    function doReset(){
    	$('#framework_knowledge_table_form').form('reset'); 
		$('#knowledge_knowledgeName').val(''); 
		$('#knowledge_knowledgeSource').combobox('setValue',null);  
	//	$('#knowledge_creator').combotree('clear');
	}
    
	//分页查询
	function doQuery()
	{
		var dataGridOptions=$('#framework_knowledge_table').datagrid('options');
		dataGridOptions.queryParams=serializeObject($('#framework_knowledge_table_form'));
		$('#framework_knowledge_table').datagrid(dataGridOptions);
		$('#framework_knowledge_table').datagrid('load');
	}
	//普通用户查询 
	function doQueryGeneral()
	{
		var dataGridOptions=$('#framework_knowledge_table').datagrid('options');
		dataGridOptions.queryParams=serializeObject($('#framework_knowledge_table_form'));
		$('#framework_knowledge_table').datagrid(dataGridOptions);
		$('#framework_knowledge_table').datagrid('load'); 
	} 
	
	
	//查询知识库 
	function doDetail(knowledgeId){  
		window.top.$('<div/>').dialog({ 
			href:'${pageContext.request.contextPath}/knowledgebase/knowlegeAction!toShowKnowledgeDetail.action?knowledgeId='+knowledgeId,
			top:($(window.top).height()-500)*0.5,
		    left:($(window.top).width()-700)*0.5,
			width:780,
			modal:true,
			title:'查看知识',
			buttons:[{  
				text : '关闭',
				iconCls : '',
				handler : function() {
					window.top.$(this).closest('.window-body').dialog('destroy');
				}
			}],
			onClose:function(){
				window.top.$(this).dialog('destroy');
			}
		});
	}
	
	//修改知识库 
	function doEdit(knowledgeId){  
		window.top.$('<div/>').dialog({ 
			href:'${pageContext.request.contextPath}/knowledgebase/knowlegeAction!toModifyKnowledgePage.action?knowledgeId='+knowledgeId,
			top:($(window.top).height()-500)*0.5,
		    left:($(window.top).width()-700)*0.5,
			width:730,
			modal:true,
			title:'修改知识',
			buttons:[{
				text:'保 存',
				iconCls : '', 
				handler:function(){
					var keyword =window.top.$("#handleKeyWord").val();
					if(keyword==""){
						window.top.$("#keywordTip").show();
						return;
					} 
					var d=window.top.$(this).closest('.window-body');
						window.top.$('#knowledge_modify_form').form('submit',{
							url:'${pageContext.request.contextPath}/knowledgebase/knowlegeAction!toModifyKnowledge.action',
							success:function(result){
								try {
									var r=$.parseJSON(result);
									//显示提示信息
									$.messager.show({
										title:'提示',
										msg:r.returnMsg
									});
									//关闭新增窗口
									d.dialog('destroy'); 
									//刷新主列表
									$('#framework_knowledge_table').datagrid('reload');																
								} catch (e) {
									$.messager.alert('提示', result);
								}
							}
						});
				}
			}],
			onClose:function(){
				window.top.$(this).dialog('destroy');
			}
		});
	}
	//新增知识库
	function doAdd(){
		window.top.$('<div/>').dialog({
			href:'${pageContext.request.contextPath}/knowledgebase/knowlegeAction!toAddKnowledgePage.action',
			top:($(window.top).height()-500)*0.5,
		    left:($(window.top).width()-700)*0.5, 
			width:730,
			modal:true,
			title:'新增知识',
			buttons:[{
				text:'保 存', 
				iconCls : '',
				handler:function(){
					var d=window.top.$(this).closest('.window-body');
						window.top.$('#framework_user_addform').form('submit',{
							url:'${pageContext.request.contextPath}/knowledgebase/knowlegeAction!toAddKnowledge.action',
							success:function(result){ 
								try {
									var r=$.parseJSON(result);
									//显示提示信息
									$.messager.show({
										title:'提示',
										msg:r.returnMsg
									});
									//关闭新增窗口
									d.dialog('destroy'); 
									//刷新主列表
									$('#framework_knowledge_table').datagrid('reload');	
									$.messager.progress('close'); 
								} catch (e) {
									$.messager.progress('close');  
									$.messager.alert('提示', result);
								}
							}
						});
				}
			}],
			onClose:function(){ 
				window.top.$(this).dialog('destroy');  
			}
		});
	}
	//单独删除
	function doDelete(knowledgeId){ 
		$.messager.confirm('删除确认', '确定要删除该条记录吗？',function(r){
			if(r){  
				$('#framework_knowledge_table_form').form('submit',{
					url:'${pageContext.request.contextPath}/knowledgebase/knowlegeAction!deleteBatchKnowledge.action?knowledgeId='+knowledgeId, 
				    success:function(result){
					   try {
							var r = $.parseJSON(result);
							$.messager.show({ 
								title : '提示',
								msg : r.returnMsg
							});
							if (r.returnFlag) {
								$('#framework_knowledge_table').datagrid('reload');
							}
						} catch (e) {
							$.messager.alert('提示', result);
						}
				    } 
		       });
			}
		});
	}
	
	//批量删除
	function doBatchDelete()
	{
		var rows=$('#framework_knowledge_table').datagrid('getChecked')
		if(rows.length<=0){
			$.messager.alert('提示','没有选择任何记录');
		}else{
			$.messager.confirm('删除确认', '确定要删除所选择的记录吗？', function(r){
				if (r){
						$('#framework_knowledge_table_form').form('submit',{
						url:'${pageContext.request.contextPath}/knowledgebase/knowlegeAction!deleteBatchKnowledge.action',
						success:function(result){
							try {
								var r = $.parseJSON(result);
								$.messager.show({
									title : '提示',
									msg : r.returnMsg
								});
								if (r.returnFlag) {
									$('#framework_knowledge_table').datagrid('reload');
								}
							} catch (e) {
								$.messager.alert('提示', result);
							}
						}
					});
				}
			}); 
		}
	}
	
	function queryUser()
  	{
   		var username=$('#query_userName').val();	
   		var query={username:username}; //把查询条件拼接成JSON
   		var grid=$("#knowledge_creator").combogrid('grid');  
   		$(grid).datagrid('options').queryParams=query; //把查询条件赋值给datagrid内部变量
   		$(grid).datagrid('load');
   	}
	function resetQuery()
  	{
		$('#query_userName').val('');
   	}
	</script>
</head>
<body class="easyui-layout">
    <form id="framework_knowledge_table_form" method="post"> 
        <div data-options="region:'north'" style="height:80px;border-bottom:none;border-top:none;">
	    	<table border="0" cellpadding="0" cellspacing="0" height="100%"  width="100%" >
	    		<tr>
	    			<td style="text-align:right;width:10%" nowrap="nowrap">
						<label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;知识作者：</label>
					</td>
					<td style="text-align:left;width:15%;" >  
	    				<input type="text" id="knowledge_creator" style="height:22px;" name="creator" /> 
					</td>
		    		<td style="text-align:right;width:10%;" nowrap="nowrap">
		    			<label>知识名称：&nbsp;</label>
		    		</td> 
					<td style="text-align:left;width:15%;" >
	    				<input type="text" id="knowledge_knowledgeName"  style="width:180px" name="knowledgeName"/>
					
					<td style="text-align:right;width:10%;"  nowrap="nowrap">
						<label>来源名称：&nbsp;</label>
					</td>
					<td style="text-align:left;width:15%;" >
	    				<input type="text" id="knowledge_knowledgeSource"  style="width:180px" name="knowledgeSource" />
					</td>
					<td colspan="2" style="width:25%;text-align:right;" nowrap="nowrap" >	      
			    		<input type="button" id="btnQuery" value="查 询" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/search.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;"/>	
			    		<input type="button" id="btnReset"  value="重 置" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/reset.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;margin-right:35px"/>				
	    			</td>
	    		</tr>
					
			</table>
	    </div>  
		<div data-options="region:'center'" style="border-top:none">  
			<table id="framework_knowledge_table"></table>
			<div id="framework_knowledge_table_toobar" class="etl_panel_title" >
				<a href="javascript:void(0);" onclick="doAdd()" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" style="float:left;">新增</a>  
				<div class="datagrid-btn-separator"></div>
				<a href="javascript:void(0);" onclick="doBatchDelete()" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">批量删除</a>
			</div> 
		</div>
    </form> 
     
    <div id="tb" style="padding:5px;height:auto">   
		    <div>  
		               用户名称 : <input id="query_userName" type="text" class="easyui-validatebox" style="width:150px" >  
		        <input type="button" id="btnQuery" onclick="queryUser()" value="查 询" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/search.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;"/>	
				<input type="button" id="btnReset" onclick="resetQuery()" value="重 置" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/reset.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;margin-right:55px"/> 
		    </div>  
	</div>
</body>
</html>
